/**
 * 
 */
package org.youisoft.summer.evaluator.function.control;

import org.youisoft.summer.evaluator.context.CalContext;
import org.youisoft.summer.evaluator.function.AbstractFunction;
import org.youisoft.summer.evaluator.operator.Operator;

/**
 * @author zijiang.jl
 *
 */
public class IfFunction extends AbstractFunction{


	@Override
	public <C,R,P> Operator<?> doInvoke(CalContext<C,R,P> context,Operator<?>... operator) {
		if(operator[0].equals(operator[1])) return operator[2];
		if(operator.length>this.minOperatorCount()) return operator[this.minOperatorCount()];
		return Operator.nullInstance;
	}


	@Override
	protected int minOperatorCount() {
		return 3;
	}

}
